<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表头栏切换</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .box {
            margin: 50px auto;
            text-align: center;
            width: 300px;
            border: 1px black solid;

        }

        .box>.top {
            font-size: 0px;
        }

        .box>.top>button {
            font-size: 18px;
            width: 60px;
            border: none;
            outline: none;
        }

        .box>.top>button.selected {
            background-color: green;
            color: red;
        }

        .box>.bottom>div {
            display: none;
            height: 300px;
            background-color: yellow;

        }

        .box>.bottom>div:nth-child(1) {
            display: block;
        }
    </style>
</head>
<script>
    window.onload = function () {
        var btns = document.getElementsByClassName('top')[0].children
        var divs = document.getElementsByClassName('bottom')[0].children
        for (let i = 0; i < btns.length; i++) {
            btns[i].onclick = function () {
                // 排他思想
                for (var j = 0; j < btns.length; j++) {
                    btns[j].className = ''
                    divs[j].style.display = "none"
                }
                this.className = 'selected'
                divs[i].style.display = "block"
            }
        }
    }
</script>

<body>
    <div class="box">
        <div class="top">
            <button class="selected">按钮1</button>
            <button>按钮2</button>
            <button>按钮3</button>
            <button>按钮4</button>
            <button>按钮5</button>
        </div>
        <div class="bottom">
            <div>盒子1</div>
            <div>盒子2</div>
            <div>盒子3</div>
            <div>盒子4</div>
            <div>盒子5</div>
        </div>
    </div>
</body>

</html>